package com.dianrui.agent;

import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.os.StrictMode;
import android.support.multidex.MultiDex;
import android.view.LayoutInflater;

import com.dianrui.agent.update.OKHttpUpdateHttpService;
import com.dianrui.agent.util.Static;
import com.tencent.bugly.crashreport.CrashReport;
import com.xuexiang.xupdate.XUpdate;
import com.zhy.http.okhttp.OkHttpUtils;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;


public class MyApplication extends Application {


    @Override
    public void onCreate() {
        super.onCreate();
        Static.CONTEXT = this;
        Static.INFLATER = LayoutInflater.from(this);
        repairAndroidOsFileUriExposedException();
        CrashReport.initCrashReport(getApplicationContext(), "f86ef82a6b", true);
        CrashReport.setIsDevelopmentDevice(getApplicationContext(), BuildConfig.DEBUG);
        loadXupdate();
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }


    public void repairAndroidOsFileUriExposedException() {
        StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
        StrictMode.setVmPolicy(builder.build());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            builder.detectFileUriExposure();
        }
    }

    private void loadXupdate() {
        XUpdate.get().isWifiOnly(false).isGet(true).isAutoMode(false).supportSilentInstall(true).setIUpdateHttpService(new OKHttpUpdateHttpService()).init(this);
    }
}
